<template>
  <div>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      :collapse="$store.state.isCollapse"
      style='border:0px'
      router
    >
      <!-- 循环 -->
      <template v-for="item in items">
        <!-- 判断是否有subs -->
        <template v-if="item.subs">
          <!-- 第一层 -->
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <!-- 循环第二层 -->
            <template v-for="subItem in item.subs">
              <!-- 第二层 -->
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template slot="title">{{ subItem.title }}</template>
                <!-- 第三层 -->
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  @click='change(threeItem)'
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>
              <!-- 第二层 -->
              <el-menu-item
                v-else
                :index="subItem.index"
                :key="subItem.index"
                @click='change(subItem)'
                >{{ subItem.title }}</el-menu-item
              >
            </template>
          </el-submenu>
        </template>
        <!-- 这个是没有 -->
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title" @click='change(item)'>{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>
<script>
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      items: [
        {
          icon: "el-icon-house",
          index: "dashboard",
          title: "系统首页",
        },
        {
          icon: "el-icon-s-grid",
          index: "table",
          title: "基础表格",
        },
        {
          icon: "el-icon-document-copy",
          index: "tabs",
          title: "tab选项卡",
        },
        {
          icon: "el-icon-document-copy",
          index: "user",
          title: "用户列表",
        },
        {
          icon: "el-icon-document-copy",
          index: "order",
          title: "订单列表",
        },
        {
          icon: "el-icon-document",
          index: "3",
          title: "表单相关",
          subs: [
            {
              index: "form",
              title: "基本表单",
            },
            {
              index: "3-2",
              title: "三级菜单",
              subs: [
                {
                  index: "editor",
                  title: "富文本编辑器",
                },
                {
                  index: "markdown",
                  title: "markdown编辑器",
                },
              ],
            },
            {
              index: "upload",
              title: "文件上传",
            },
          ],
        },
        {
          icon: "el-icon-loading",
          index: "icon",
          title: "自定义图标",
        },
        {
          icon: "el-icon-pie-chart",
          index: "charts",
          title: "schart图表",
        },
        {
          icon: "el-icon-rank",
          index: "6",
          title: "拖拽组件",
          subs: [
            {
              index: "drag",
              title: "拖拽列表",
            },
            {
              index: "dialog",
              title: "拖拽弹框",
            },
          ],
        },
        {
          icon: "el-icon-orange",
          index: "i18n",
          title: "国际化功能",
        },
        {
          icon: "el-icon-warning-outline",
          index: "7",
          title: "错误处理",
          subs: [
            {
              index: "permission",
              title: "权限测试",
            },
            {
              index: "404",
              title: "404页面",
            },
          ],
        },
        {
          icon: "el-icon-s-promotion",
          index: "8",
          title: "商品页面",
          subs: [
            {
              index: "goods",
              title: "商品分类",
            },
            {
              index: "goodslist",
              title: "商品列表",
            },
          ],
        },
        // {
        //   icon: "el-icon-s-promotion",
        //   index: "/donate",
        //   title: "支持作者",
        // },
      ],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.setHeight();
    window.addEventListener("resize", this.setHeight);
  },
  methods: {
    setHeight() {
      let html = document.documentElement || document.body;
      let html_height = html.clientHeight;
      // console.log(html_height);
      let leftMenu = document.querySelector(".el-menu");
      leftMenu.style.height = html_height - 80 + "px";
    },
    change(data){
      this.$store.commit("change",data)
    }
  },
};
</script>
<style scoped>
.el-menu {
  height: 900px;
}
</style>